{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b144c684",
   "metadata": {},
   "source": [
    "## 第二章习题\n",
    "\n",
    "### 一、填空题\n",
    "\n",
    "1.列表的`sort()`方法没有返回值,或者说返回值为____None____."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fbb67025",
   "metadata": {},
   "source": [
    "2.已知列表 `data=[1,2,30 4]`，那么`data[2:100]`的值为__[304]_____."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b542335f",
   "metadata": {},
   "source": [
    "3.己知`x=3`和`y=5`,那么执行语句`x,y=y,x`之后，`y`的值为__3____."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d2779e9",
   "metadata": {},
   "source": [
    "4．已知字典 `data= {'a;97, 'A' :65}`,那么`data.get('a', None)`的值为______97__."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0745597",
   "metadata": {},
   "source": [
    "### 二、判断题\n",
    "\n",
    "1.生成器表达式的计算结果是一个元组。`(  错  )`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b93510d2",
   "metadata": {},
   "source": [
    "2．包含列表的元组可以作为字典的“键”。`(  错  )`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "10e6d58c",
   "metadata": {},
   "source": [
    "3．包含列表的元组不可以作为集合的元素。`(  对  )`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eee10686",
   "metadata": {},
   "source": [
    "4．列表的`rindex()`方法返回指定元素在列表中最后一次出现的位置。`(   对 )`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6e244a97",
   "metadata": {},
   "source": [
    "### 三、编程题\n",
    "\n",
    "1.输入一个字符串，输出其中每个字符的出现次数。要求使用标准库`collotections`中的`Counter`类,请自行查阅相关用法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "c09e30b9",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串：2,3,4,5\n",
      "Counter({',': 3, '2': 1, '3': 1, '4': 1, '5': 1})\n"
     ]
    }
   ],
   "source": [
    "from collections import Counter\n",
    "s = input('请输入一个字符串：')\n",
    "frequencies=Counter(s)\n",
    "print(frequencies)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2398fa15",
   "metadata": {},
   "source": [
    "2．输入一个字符串,输出其中只出现了一次的字符及其下标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b7afc3dd",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串：1,4,5,2\n",
      "[('1', 0), ('4', 2), ('5', 4), ('2', 6)]\n"
     ]
    }
   ],
   "source": [
    "s=input(\"请输入一个字符串：\")\n",
    "positions = [(ch,index) for index,ch in enumerate(s) if s.index(ch)==s.rindex(ch)]\n",
    "print(positions)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ba87512",
   "metadata": {},
   "source": [
    "3．输入一个字符串,输出其中每个唯一字符最后一次出现的下标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ce92761",
   "metadata": {},
   "outputs": [],
   "source": [
    "s=input('请输入一个字符串：')\n",
    "positions=[]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "92afa96e",
   "metadata": {},
   "source": [
    "4．输入包含若干集合的列表，输出这些集合的并集。提示:使用`reduce()`函数和`operator`模块中的运算实现多个集合的并集。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "7dc3a058",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入包含若干集合的列表{12,45,32}\n",
      "45\n"
     ]
    }
   ],
   "source": [
    "from functools import reduce\n",
    "from operator  import  __or__\n",
    "s=eval(input(\"请输入包含若干集合的列表\"))\n",
    "print(reduce(__or__ ,s))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4721c191",
   "metadata": {},
   "source": [
    "5．输入一个字符串,检查该字符串是否为回文（正着读和反看读都一样的字符串)，如果是就输出`Yes`，否则输出`No`。要求使用切片实现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "4b2a7649",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串2，4，7，1\n",
      "No\n"
     ]
    }
   ],
   "source": [
    "\n",
    "alist1 = input('请输入一个字符串')\n",
    "\n",
    "alist2 =alist1[::-1]\n",
    "if alist1 == alist2:\n",
    "    print('Yes')\n",
    "else:\n",
    "    print('No')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0413f750",
   "metadata": {},
   "source": [
    "## 课本上65页课后习题"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7999216c",
   "metadata": {},
   "source": [
    "可迭代对象"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5b5dd6a",
   "metadata": {},
   "source": [
    "4"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ff1246ff",
   "metadata": {},
   "source": [
    "None\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "646ae9be",
   "metadata": {},
   "source": [
    "remove（)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "54209a4b",
   "metadata": {},
   "source": [
    "[3,7,9,11]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15fbf2db",
   "metadata": {},
   "source": [
    "{};键;值；键\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a531a7c",
   "metadata": {},
   "source": [
    "items()；keys（);values（）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8cb6ef24",
   "metadata": {},
   "source": [
    "[dict(zip(a,b))]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e9e097e5",
   "metadata": {},
   "source": [
    "b=a[::3]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0d371610",
   "metadata": {},
   "source": [
    "5 for in range(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4388017e",
   "metadata": {},
   "source": [
    "不可以"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "79211a62",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]\n"
     ]
    }
   ],
   "source": [
    "def prime(x):                       \n",
    "    for i in range(2,x):\n",
    "        if x%i==0:\n",
    "            return False\n",
    "        if i==x-1:\n",
    "            return True\n",
    "output=filter(prime,range(2,1001))\n",
    "print(list(output))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ebd220db",
   "metadata": {},
   "source": [
    "尽量不破环列表顺序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "c7209b64",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[84, 68, 69, 2, 62, 23, 55, 98, 98, 57, 84, 19, 47, 94, 97, 53, 61, 58, 50, 54, 32, 93, 16, 87, 82, 92, 48, 60, 98, 92, 20, 78, 50, 38, 40, 38, 21, 68, 34, 72, 41, 18, 19, 78, 86, 33, 55, 77, 57, 11, 43, 62, 44, 76, 20, 73, 91, 77, 65, 55, 94, 5, 13, 56, 28, 44, 76, 45, 89, 25, 75, 70, 43, 4, 27, 92, 69, 61, 40, 95, 52, 14, 57, 66, 76, 52, 92, 77, 89, 10, 61, 90, 74, 83, 48, 75, 93, 68, 31, 59, 20, 22, 63, 51, 100, 95, 97, 92, 78, 73, 99, 17, 57, 14, 78, 25, 76, 57, 31, 25, 42, 64, 81, 53, 52, 42, 34, 74, 61, 33, 1, 66, 22, 8, 93, 43, 71, 74, 58, 66, 17, 36, 93, 91, 77, 41, 39, 92, 10, 33, 21, 93, 91, 1, 61, 6, 9, 95, 44, 66, 66, 96, 18, 18, 42, 58, 97, 84, 56, 16, 62, 55, 59, 5, 26, 16, 79, 45, 41, 91, 18, 36, 50, 73, 2, 70, 72, 23, 31, 0, 43, 99, 19, 76, 78, 72, 0, 46, 16, 75, 3, 73, 75, 20, 35, 71, 7, 72, 84, 25, 50, 53, 91, 70, 47, 12, 77, 41, 67, 84, 94, 89, 69, 13, 40, 10, 66, 23, 97, 11, 97, 9, 1, 85, 43, 86, 86, 55, 27, 16, 34, 21, 19, 4, 90, 17, 41, 2, 63, 14, 49, 26, 81, 14, 69, 95, 3, 39, 29, 69, 64, 86, 79, 37, 94, 68, 71, 30, 86, 85, 45, 8, 12, 2, 58, 46, 85, 46, 97, 35, 12, 33, 46, 7, 4, 35, 21, 8, 8, 5, 88, 16, 91, 79, 64, 17, 22, 79, 36, 98, 13, 52, 19, 34, 31, 9, 49, 91, 28, 30, 79, 69, 82, 70, 73, 35, 21, 56, 34, 0, 100, 86, 14, 52, 84, 21, 2, 34, 74, 83, 24, 98, 75, 26, 9, 66, 74, 37, 0, 29, 10, 2, 51, 69, 84, 15, 93, 78, 69, 28, 72, 24, 81, 73, 85, 67, 57, 78, 88, 11, 31, 28, 26, 63, 46, 34, 89, 100, 94, 6, 92, 32, 51, 69, 29, 7, 96, 23, 22, 93, 9, 17, 7, 73, 9, 19, 37, 19, 2, 11, 42, 40, 45, 89, 62, 4, 59, 19, 37, 4, 30, 72, 67, 59, 18, 98, 89, 79, 14, 16, 80, 96, 57, 58, 38, 90, 90, 8, 61, 70, 72, 8, 93, 35, 90, 92, 52, 34, 23, 6, 22, 35, 85, 29, 98, 20, 68, 19, 97, 73, 85, 30, 73, 12, 96, 9, 8, 31, 19, 74, 24, 34, 22, 35, 68, 4, 54, 7, 61, 37, 53, 100, 40, 54, 13, 61, 61, 6, 45, 100, 25, 99, 95, 4, 28, 66, 59, 15, 91, 41, 77, 75, 80, 72, 71, 12, 41, 38, 23, 97, 62, 67, 59, 56, 79, 14, 33, 41, 16, 23, 68, 41, 63, 76, 72, 31, 44, 15, 62, 72, 85, 37, 47, 21, 71, 29, 21, 56, 70, 96, 94, 44, 45, 43, 78, 15, 41, 49, 59, 32, 67, 58, 49, 99, 46, 79, 33, 97, 13, 78, 11, 41, 74, 20, 82, 70, 33, 75, 99, 13, 33, 5, 43, 43, 85, 29, 96, 88, 81, 30, 48, 37, 17, 60, 45, 48, 98, 45, 62, 13, 30, 76, 85, 98, 28, 20, 69, 12, 20, 30, 97, 47, 77, 88, 91, 77, 20, 26, 31, 70, 38, 26, 9, 58, 6, 6, 73, 39, 45, 70, 1, 96, 38, 50, 80, 18, 28, 69, 83, 87, 53, 55, 35, 5, 95, 32, 75, 9, 42, 90, 52, 3, 95, 5, 66, 96, 18, 52, 59, 65, 40, 24, 86, 34, 62, 41, 14, 84, 82, 77, 94, 98, 71, 20, 91, 36, 31, 46, 44, 70, 3, 18, 84, 37, 58, 38, 63, 54, 91, 11, 0, 29, 15, 49, 34, 62, 51, 32, 97, 81, 67, 77, 48, 17, 76, 94, 52, 30, 58, 29, 68, 23, 66, 74, 74, 44, 15, 40, 14, 92, 41, 2, 10, 72, 26, 80, 84, 23, 90, 44, 97, 12, 57, 34, 77, 33, 82, 50, 35, 90, 99, 45, 84, 96, 47, 100, 5, 32, 24, 70, 90, 94, 91, 6, 86, 32, 26, 35, 65, 86, 54, 98, 54, 77, 80, 31, 40, 73, 85, 71, 22, 70, 96, 91, 29, 69, 82, 47, 29, 95, 96, 83, 36, 60, 18, 15, 71, 46, 54, 65, 2, 36, 54, 21, 67, 0, 24, 72, 29, 61, 28, 0, 76, 14, 86, 59, 37, 87, 21, 22, 3, 100, 83, 66, 18, 42, 13, 30, 28, 47, 16, 70, 37, 55, 19, 50, 3, 12, 26, 23, 34, 56, 21, 60, 86, 31, 38, 91, 31, 92, 80, 36, 11, 82, 46, 99, 30, 78, 74, 38, 84, 45, 36, 83, 77, 76, 100, 14, 34, 3, 75, 81, 26, 64, 32, 28, 45, 62, 1, 15, 68, 68, 61, 66, 70, 3, 31, 68, 23, 45, 99, 1, 59, 35, 22, 64, 0, 15, 7, 29, 1, 71, 99, 33, 93, 21, 6, 75, 32, 98, 99, 56, 35, 95, 78, 0, 65, 90, 51, 82, 96, 40, 89, 0, 49, 37, 96, 27, 1, 18, 14, 64, 24, 77, 27, 86, 79, 12, 79, 97, 13, 74, 95, 71, 80, 48, 70, 39, 80, 81, 26, 37, 60, 75, 25, 59, 87, 54, 91, 63, 65, 90, 68, 50, 71, 0, 33, 46, 77, 8, 59, 14, 71, 98, 73, 85, 36, 68, 80, 46, 3, 28, 63, 6, 97, 0, 22, 8, 44, 48, 19, 90, 41, 55, 99, 68, 56, 77, 19, 81, 77, 52, 83, 56, 37, 73, 88, 71, 39, 82, 32, 77, 80, 58, 95, 35, 27, 80, 44, 48, 39, 95, 23, 27, 84, 51, 13, 79, 35, 74, 42, 77, 76, 81, 40, 4, 92, 64, 59, 63]\n",
      "84 : 13\n",
      "68 : 14\n",
      "69 : 12\n",
      "2 : 9\n",
      "62 : 10\n",
      "23 : 12\n",
      "55 : 8\n",
      "98 : 13\n",
      "98 : 13\n",
      "57 : 8\n",
      "84 : 13\n",
      "19 : 13\n",
      "47 : 7\n",
      "94 : 9\n",
      "97 : 14\n",
      "53 : 5\n",
      "61 : 11\n",
      "58 : 10\n",
      "50 : 8\n",
      "54 : 9\n",
      "32 : 10\n",
      "93 : 9\n",
      "16 : 9\n",
      "87 : 4\n",
      "82 : 9\n",
      "92 : 11\n",
      "48 : 8\n",
      "60 : 5\n",
      "98 : 13\n",
      "92 : 11\n",
      "20 : 10\n",
      "78 : 11\n",
      "50 : 8\n",
      "38 : 9\n",
      "40 : 10\n",
      "38 : 9\n",
      "21 : 12\n",
      "68 : 14\n",
      "34 : 14\n",
      "72 : 12\n",
      "41 : 14\n",
      "18 : 11\n",
      "19 : 13\n",
      "78 : 11\n",
      "86 : 12\n",
      "33 : 11\n",
      "55 : 8\n",
      "77 : 19\n",
      "57 : 8\n",
      "11 : 7\n",
      "43 : 8\n",
      "62 : 10\n",
      "44 : 10\n",
      "76 : 11\n",
      "20 : 10\n",
      "73 : 13\n",
      "91 : 15\n",
      "77 : 19\n",
      "65 : 6\n",
      "55 : 8\n",
      "94 : 9\n",
      "5 : 7\n",
      "13 : 10\n",
      "56 : 9\n",
      "28 : 11\n",
      "44 : 10\n",
      "76 : 11\n",
      "45 : 13\n",
      "89 : 7\n",
      "25 : 6\n",
      "75 : 11\n",
      "70 : 15\n",
      "43 : 8\n",
      "4 : 8\n",
      "27 : 6\n",
      "92 : 11\n",
      "69 : 12\n",
      "61 : 11\n",
      "40 : 10\n",
      "95 : 12\n",
      "52 : 10\n",
      "14 : 13\n",
      "57 : 8\n",
      "66 : 12\n",
      "76 : 11\n",
      "52 : 10\n",
      "92 : 11\n",
      "77 : 19\n",
      "89 : 7\n",
      "10 : 5\n",
      "61 : 11\n",
      "90 : 12\n",
      "74 : 12\n",
      "83 : 7\n",
      "48 : 8\n",
      "75 : 11\n",
      "93 : 9\n",
      "68 : 14\n",
      "31 : 13\n",
      "59 : 13\n",
      "20 : 10\n",
      "22 : 10\n",
      "63 : 8\n",
      "51 : 6\n",
      "100 : 8\n",
      "95 : 12\n",
      "97 : 14\n",
      "92 : 11\n",
      "78 : 11\n",
      "73 : 13\n",
      "99 : 11\n",
      "17 : 7\n",
      "57 : 8\n",
      "14 : 13\n",
      "78 : 11\n",
      "25 : 6\n",
      "76 : 11\n",
      "57 : 8\n",
      "31 : 13\n",
      "25 : 6\n",
      "42 : 7\n",
      "64 : 7\n",
      "81 : 9\n",
      "53 : 5\n",
      "52 : 10\n",
      "42 : 7\n",
      "34 : 14\n",
      "74 : 12\n",
      "61 : 11\n",
      "33 : 11\n",
      "1 : 8\n",
      "66 : 12\n",
      "22 : 10\n",
      "8 : 9\n",
      "93 : 9\n",
      "43 : 8\n",
      "71 : 13\n",
      "74 : 12\n",
      "58 : 10\n",
      "66 : 12\n",
      "17 : 7\n",
      "36 : 9\n",
      "93 : 9\n",
      "91 : 15\n",
      "77 : 19\n",
      "41 : 14\n",
      "39 : 6\n",
      "92 : 11\n",
      "10 : 5\n",
      "33 : 11\n",
      "21 : 12\n",
      "93 : 9\n",
      "91 : 15\n",
      "1 : 8\n",
      "61 : 11\n",
      "6 : 9\n",
      "9 : 9\n",
      "95 : 12\n",
      "44 : 10\n",
      "66 : 12\n",
      "66 : 12\n",
      "96 : 13\n",
      "18 : 11\n",
      "18 : 11\n",
      "42 : 7\n",
      "58 : 10\n",
      "97 : 14\n",
      "84 : 13\n",
      "56 : 9\n",
      "16 : 9\n",
      "62 : 10\n",
      "55 : 8\n",
      "59 : 13\n",
      "5 : 7\n",
      "26 : 11\n",
      "16 : 9\n",
      "79 : 11\n",
      "45 : 13\n",
      "41 : 14\n",
      "91 : 15\n",
      "18 : 11\n",
      "36 : 9\n",
      "50 : 8\n",
      "73 : 13\n",
      "2 : 9\n",
      "70 : 15\n",
      "72 : 12\n",
      "23 : 12\n",
      "31 : 13\n",
      "0 : 12\n",
      "43 : 8\n",
      "99 : 11\n",
      "19 : 13\n",
      "76 : 11\n",
      "78 : 11\n",
      "72 : 12\n",
      "0 : 12\n",
      "46 : 11\n",
      "16 : 9\n",
      "75 : 11\n",
      "3 : 9\n",
      "73 : 13\n",
      "75 : 11\n",
      "20 : 10\n",
      "35 : 14\n",
      "71 : 13\n",
      "7 : 6\n",
      "72 : 12\n",
      "84 : 13\n",
      "25 : 6\n",
      "50 : 8\n",
      "53 : 5\n",
      "91 : 15\n",
      "70 : 15\n",
      "47 : 7\n",
      "12 : 9\n",
      "77 : 19\n",
      "41 : 14\n",
      "67 : 7\n",
      "84 : 13\n",
      "94 : 9\n",
      "89 : 7\n",
      "69 : 12\n",
      "13 : 10\n",
      "40 : 10\n",
      "10 : 5\n",
      "66 : 12\n",
      "23 : 12\n",
      "97 : 14\n",
      "11 : 7\n",
      "97 : 14\n",
      "9 : 9\n",
      "1 : 8\n",
      "85 : 11\n",
      "43 : 8\n",
      "86 : 12\n",
      "86 : 12\n",
      "55 : 8\n",
      "27 : 6\n",
      "16 : 9\n",
      "34 : 14\n",
      "21 : 12\n",
      "19 : 13\n",
      "4 : 8\n",
      "90 : 12\n",
      "17 : 7\n",
      "41 : 14\n",
      "2 : 9\n",
      "63 : 8\n",
      "14 : 13\n",
      "49 : 6\n",
      "26 : 11\n",
      "81 : 9\n",
      "14 : 13\n",
      "69 : 12\n",
      "95 : 12\n",
      "3 : 9\n",
      "39 : 6\n",
      "29 : 12\n",
      "69 : 12\n",
      "64 : 7\n",
      "86 : 12\n",
      "79 : 11\n",
      "37 : 13\n",
      "94 : 9\n",
      "68 : 14\n",
      "71 : 13\n",
      "30 : 10\n",
      "86 : 12\n",
      "85 : 11\n",
      "45 : 13\n",
      "8 : 9\n",
      "12 : 9\n",
      "2 : 9\n",
      "58 : 10\n",
      "46 : 11\n",
      "85 : 11\n",
      "46 : 11\n",
      "97 : 14\n",
      "35 : 14\n",
      "12 : 9\n",
      "33 : 11\n",
      "46 : 11\n",
      "7 : 6\n",
      "4 : 8\n",
      "35 : 14\n",
      "21 : 12\n",
      "8 : 9\n",
      "8 : 9\n",
      "5 : 7\n",
      "88 : 5\n",
      "16 : 9\n",
      "91 : 15\n",
      "79 : 11\n",
      "64 : 7\n",
      "17 : 7\n",
      "22 : 10\n",
      "79 : 11\n",
      "36 : 9\n",
      "98 : 13\n",
      "13 : 10\n",
      "52 : 10\n",
      "19 : 13\n",
      "34 : 14\n",
      "31 : 13\n",
      "9 : 9\n",
      "49 : 6\n",
      "91 : 15\n",
      "28 : 11\n",
      "30 : 10\n",
      "79 : 11\n",
      "69 : 12\n",
      "82 : 9\n",
      "70 : 15\n",
      "73 : 13\n",
      "35 : 14\n",
      "21 : 12\n",
      "56 : 9\n",
      "34 : 14\n",
      "0 : 12\n",
      "100 : 8\n",
      "86 : 12\n",
      "14 : 13\n",
      "52 : 10\n",
      "84 : 13\n",
      "21 : 12\n",
      "2 : 9\n",
      "34 : 14\n",
      "74 : 12\n",
      "83 : 7\n",
      "24 : 7\n",
      "98 : 13\n",
      "75 : 11\n",
      "26 : 11\n",
      "9 : 9\n",
      "66 : 12\n",
      "74 : 12\n",
      "37 : 13\n",
      "0 : 12\n",
      "29 : 12\n",
      "10 : 5\n",
      "2 : 9\n",
      "51 : 6\n",
      "69 : 12\n",
      "84 : 13\n",
      "15 : 9\n",
      "93 : 9\n",
      "78 : 11\n",
      "69 : 12\n",
      "28 : 11\n",
      "72 : 12\n",
      "24 : 7\n",
      "81 : 9\n",
      "73 : 13\n",
      "85 : 11\n",
      "67 : 7\n",
      "57 : 8\n",
      "78 : 11\n",
      "88 : 5\n",
      "11 : 7\n",
      "31 : 13\n",
      "28 : 11\n",
      "26 : 11\n",
      "63 : 8\n",
      "46 : 11\n",
      "34 : 14\n",
      "89 : 7\n",
      "100 : 8\n",
      "94 : 9\n",
      "6 : 9\n",
      "92 : 11\n",
      "32 : 10\n",
      "51 : 6\n",
      "69 : 12\n",
      "29 : 12\n",
      "7 : 6\n",
      "96 : 13\n",
      "23 : 12\n",
      "22 : 10\n",
      "93 : 9\n",
      "9 : 9\n",
      "17 : 7\n",
      "7 : 6\n",
      "73 : 13\n",
      "9 : 9\n",
      "19 : 13\n",
      "37 : 13\n",
      "19 : 13\n",
      "2 : 9\n",
      "11 : 7\n",
      "42 : 7\n",
      "40 : 10\n",
      "45 : 13\n",
      "89 : 7\n",
      "62 : 10\n",
      "4 : 8\n",
      "59 : 13\n",
      "19 : 13\n",
      "37 : 13\n",
      "4 : 8\n",
      "30 : 10\n",
      "72 : 12\n",
      "67 : 7\n",
      "59 : 13\n",
      "18 : 11\n",
      "98 : 13\n",
      "89 : 7\n",
      "79 : 11\n",
      "14 : 13\n",
      "16 : 9\n",
      "80 : 11\n",
      "96 : 13\n",
      "57 : 8\n",
      "58 : 10\n",
      "38 : 9\n",
      "90 : 12\n",
      "90 : 12\n",
      "8 : 9\n",
      "61 : 11\n",
      "70 : 15\n",
      "72 : 12\n",
      "8 : 9\n",
      "93 : 9\n",
      "35 : 14\n",
      "90 : 12\n",
      "92 : 11\n",
      "52 : 10\n",
      "34 : 14\n",
      "23 : 12\n",
      "6 : 9\n",
      "22 : 10\n",
      "35 : 14\n",
      "85 : 11\n",
      "29 : 12\n",
      "98 : 13\n",
      "20 : 10\n",
      "68 : 14\n",
      "19 : 13\n",
      "97 : 14\n",
      "73 : 13\n",
      "85 : 11\n",
      "30 : 10\n",
      "73 : 13\n",
      "12 : 9\n",
      "96 : 13\n",
      "9 : 9\n",
      "8 : 9\n",
      "31 : 13\n",
      "19 : 13\n",
      "74 : 12\n",
      "24 : 7\n",
      "34 : 14\n",
      "22 : 10\n",
      "35 : 14\n",
      "68 : 14\n",
      "4 : 8\n",
      "54 : 9\n",
      "7 : 6\n",
      "61 : 11\n",
      "37 : 13\n",
      "53 : 5\n",
      "100 : 8\n",
      "40 : 10\n",
      "54 : 9\n",
      "13 : 10\n",
      "61 : 11\n",
      "61 : 11\n",
      "6 : 9\n",
      "45 : 13\n",
      "100 : 8\n",
      "25 : 6\n",
      "99 : 11\n",
      "95 : 12\n",
      "4 : 8\n",
      "28 : 11\n",
      "66 : 12\n",
      "59 : 13\n",
      "15 : 9\n",
      "91 : 15\n",
      "41 : 14\n",
      "77 : 19\n",
      "75 : 11\n",
      "80 : 11\n",
      "72 : 12\n",
      "71 : 13\n",
      "12 : 9\n",
      "41 : 14\n",
      "38 : 9\n",
      "23 : 12\n",
      "97 : 14\n",
      "62 : 10\n",
      "67 : 7\n",
      "59 : 13\n",
      "56 : 9\n",
      "79 : 11\n",
      "14 : 13\n",
      "33 : 11\n",
      "41 : 14\n",
      "16 : 9\n",
      "23 : 12\n",
      "68 : 14\n",
      "41 : 14\n",
      "63 : 8\n",
      "76 : 11\n",
      "72 : 12\n",
      "31 : 13\n",
      "44 : 10\n",
      "15 : 9\n",
      "62 : 10\n",
      "72 : 12\n",
      "85 : 11\n",
      "37 : 13\n",
      "47 : 7\n",
      "21 : 12\n",
      "71 : 13\n",
      "29 : 12\n",
      "21 : 12\n",
      "56 : 9\n",
      "70 : 15\n",
      "96 : 13\n",
      "94 : 9\n",
      "44 : 10\n",
      "45 : 13\n",
      "43 : 8\n",
      "78 : 11\n",
      "15 : 9\n",
      "41 : 14\n",
      "49 : 6\n",
      "59 : 13\n",
      "32 : 10\n",
      "67 : 7\n",
      "58 : 10\n",
      "49 : 6\n",
      "99 : 11\n",
      "46 : 11\n",
      "79 : 11\n",
      "33 : 11\n",
      "97 : 14\n",
      "13 : 10\n",
      "78 : 11\n",
      "11 : 7\n",
      "41 : 14\n",
      "74 : 12\n",
      "20 : 10\n",
      "82 : 9\n",
      "70 : 15\n",
      "33 : 11\n",
      "75 : 11\n",
      "99 : 11\n",
      "13 : 10\n",
      "33 : 11\n",
      "5 : 7\n",
      "43 : 8\n",
      "43 : 8\n",
      "85 : 11\n",
      "29 : 12\n",
      "96 : 13\n",
      "88 : 5\n",
      "81 : 9\n",
      "30 : 10\n",
      "48 : 8\n",
      "37 : 13\n",
      "17 : 7\n",
      "60 : 5\n",
      "45 : 13\n",
      "48 : 8\n",
      "98 : 13\n",
      "45 : 13\n",
      "62 : 10\n",
      "13 : 10\n",
      "30 : 10\n",
      "76 : 11\n",
      "85 : 11\n",
      "98 : 13\n",
      "28 : 11\n",
      "20 : 10\n",
      "69 : 12\n",
      "12 : 9\n",
      "20 : 10\n",
      "30 : 10\n",
      "97 : 14\n",
      "47 : 7\n",
      "77 : 19\n",
      "88 : 5\n",
      "91 : 15\n",
      "77 : 19\n",
      "20 : 10\n",
      "26 : 11\n",
      "31 : 13\n",
      "70 : 15\n",
      "38 : 9\n",
      "26 : 11\n",
      "9 : 9\n",
      "58 : 10\n",
      "6 : 9\n",
      "6 : 9\n",
      "73 : 13\n",
      "39 : 6\n",
      "45 : 13\n",
      "70 : 15\n",
      "1 : 8\n",
      "96 : 13\n",
      "38 : 9\n",
      "50 : 8\n",
      "80 : 11\n",
      "18 : 11\n",
      "28 : 11\n",
      "69 : 12\n",
      "83 : 7\n",
      "87 : 4\n",
      "53 : 5\n",
      "55 : 8\n",
      "35 : 14\n",
      "5 : 7\n",
      "95 : 12\n",
      "32 : 10\n",
      "75 : 11\n",
      "9 : 9\n",
      "42 : 7\n",
      "90 : 12\n",
      "52 : 10\n",
      "3 : 9\n",
      "95 : 12\n",
      "5 : 7\n",
      "66 : 12\n",
      "96 : 13\n",
      "18 : 11\n",
      "52 : 10\n",
      "59 : 13\n",
      "65 : 6\n",
      "40 : 10\n",
      "24 : 7\n",
      "86 : 12\n",
      "34 : 14\n",
      "62 : 10\n",
      "41 : 14\n",
      "14 : 13\n",
      "84 : 13\n",
      "82 : 9\n",
      "77 : 19\n",
      "94 : 9\n",
      "98 : 13\n",
      "71 : 13\n",
      "20 : 10\n",
      "91 : 15\n",
      "36 : 9\n",
      "31 : 13\n",
      "46 : 11\n",
      "44 : 10\n",
      "70 : 15\n",
      "3 : 9\n",
      "18 : 11\n",
      "84 : 13\n",
      "37 : 13\n",
      "58 : 10\n",
      "38 : 9\n",
      "63 : 8\n",
      "54 : 9\n",
      "91 : 15\n",
      "11 : 7\n",
      "0 : 12\n",
      "29 : 12\n",
      "15 : 9\n",
      "49 : 6\n",
      "34 : 14\n",
      "62 : 10\n",
      "51 : 6\n",
      "32 : 10\n",
      "97 : 14\n",
      "81 : 9\n",
      "67 : 7\n",
      "77 : 19\n",
      "48 : 8\n",
      "17 : 7\n",
      "76 : 11\n",
      "94 : 9\n",
      "52 : 10\n",
      "30 : 10\n",
      "58 : 10\n",
      "29 : 12\n",
      "68 : 14\n",
      "23 : 12\n",
      "66 : 12\n",
      "74 : 12\n",
      "74 : 12\n",
      "44 : 10\n",
      "15 : 9\n",
      "40 : 10\n",
      "14 : 13\n",
      "92 : 11\n",
      "41 : 14\n",
      "2 : 9\n",
      "10 : 5\n",
      "72 : 12\n",
      "26 : 11\n",
      "80 : 11\n",
      "84 : 13\n",
      "23 : 12\n",
      "90 : 12\n",
      "44 : 10\n",
      "97 : 14\n",
      "12 : 9\n",
      "57 : 8\n",
      "34 : 14\n",
      "77 : 19\n",
      "33 : 11\n",
      "82 : 9\n",
      "50 : 8\n",
      "35 : 14\n",
      "90 : 12\n",
      "99 : 11\n",
      "45 : 13\n",
      "84 : 13\n",
      "96 : 13\n",
      "47 : 7\n",
      "100 : 8\n",
      "5 : 7\n",
      "32 : 10\n",
      "24 : 7\n",
      "70 : 15\n",
      "90 : 12\n",
      "94 : 9\n",
      "91 : 15\n",
      "6 : 9\n",
      "86 : 12\n",
      "32 : 10\n",
      "26 : 11\n",
      "35 : 14\n",
      "65 : 6\n",
      "86 : 12\n",
      "54 : 9\n",
      "98 : 13\n",
      "54 : 9\n",
      "77 : 19\n",
      "80 : 11\n",
      "31 : 13\n",
      "40 : 10\n",
      "73 : 13\n",
      "85 : 11\n",
      "71 : 13\n",
      "22 : 10\n",
      "70 : 15\n",
      "96 : 13\n",
      "91 : 15\n",
      "29 : 12\n",
      "69 : 12\n",
      "82 : 9\n",
      "47 : 7\n",
      "29 : 12\n",
      "95 : 12\n",
      "96 : 13\n",
      "83 : 7\n",
      "36 : 9\n",
      "60 : 5\n",
      "18 : 11\n",
      "15 : 9\n",
      "71 : 13\n",
      "46 : 11\n",
      "54 : 9\n",
      "65 : 6\n",
      "2 : 9\n",
      "36 : 9\n",
      "54 : 9\n",
      "21 : 12\n",
      "67 : 7\n",
      "0 : 12\n",
      "24 : 7\n",
      "72 : 12\n",
      "29 : 12\n",
      "61 : 11\n",
      "28 : 11\n",
      "0 : 12\n",
      "76 : 11\n",
      "14 : 13\n",
      "86 : 12\n",
      "59 : 13\n",
      "37 : 13\n",
      "87 : 4\n",
      "21 : 12\n",
      "22 : 10\n",
      "3 : 9\n",
      "100 : 8\n",
      "83 : 7\n",
      "66 : 12\n",
      "18 : 11\n",
      "42 : 7\n",
      "13 : 10\n",
      "30 : 10\n",
      "28 : 11\n",
      "47 : 7\n",
      "16 : 9\n",
      "70 : 15\n",
      "37 : 13\n",
      "55 : 8\n",
      "19 : 13\n",
      "50 : 8\n",
      "3 : 9\n",
      "12 : 9\n",
      "26 : 11\n",
      "23 : 12\n",
      "34 : 14\n",
      "56 : 9\n",
      "21 : 12\n",
      "60 : 5\n",
      "86 : 12\n",
      "31 : 13\n",
      "38 : 9\n",
      "91 : 15\n",
      "31 : 13\n",
      "92 : 11\n",
      "80 : 11\n",
      "36 : 9\n",
      "11 : 7\n",
      "82 : 9\n",
      "46 : 11\n",
      "99 : 11\n",
      "30 : 10\n",
      "78 : 11\n",
      "74 : 12\n",
      "38 : 9\n",
      "84 : 13\n",
      "45 : 13\n",
      "36 : 9\n",
      "83 : 7\n",
      "77 : 19\n",
      "76 : 11\n",
      "100 : 8\n",
      "14 : 13\n",
      "34 : 14\n",
      "3 : 9\n",
      "75 : 11\n",
      "81 : 9\n",
      "26 : 11\n",
      "64 : 7\n",
      "32 : 10\n",
      "28 : 11\n",
      "45 : 13\n",
      "62 : 10\n",
      "1 : 8\n",
      "15 : 9\n",
      "68 : 14\n",
      "68 : 14\n",
      "61 : 11\n",
      "66 : 12\n",
      "70 : 15\n",
      "3 : 9\n",
      "31 : 13\n",
      "68 : 14\n",
      "23 : 12\n",
      "45 : 13\n",
      "99 : 11\n",
      "1 : 8\n",
      "59 : 13\n",
      "35 : 14\n",
      "22 : 10\n",
      "64 : 7\n",
      "0 : 12\n",
      "15 : 9\n",
      "7 : 6\n",
      "29 : 12\n",
      "1 : 8\n",
      "71 : 13\n",
      "99 : 11\n",
      "33 : 11\n",
      "93 : 9\n",
      "21 : 12\n",
      "6 : 9\n",
      "75 : 11\n",
      "32 : 10\n",
      "98 : 13\n",
      "99 : 11\n",
      "56 : 9\n",
      "35 : 14\n",
      "95 : 12\n",
      "78 : 11\n",
      "0 : 12\n",
      "65 : 6\n",
      "90 : 12\n",
      "51 : 6\n",
      "82 : 9\n",
      "96 : 13\n",
      "40 : 10\n",
      "89 : 7\n",
      "0 : 12\n",
      "49 : 6\n",
      "37 : 13\n",
      "96 : 13\n",
      "27 : 6\n",
      "1 : 8\n",
      "18 : 11\n",
      "14 : 13\n",
      "64 : 7\n",
      "24 : 7\n",
      "77 : 19\n",
      "27 : 6\n",
      "86 : 12\n",
      "79 : 11\n",
      "12 : 9\n",
      "79 : 11\n",
      "97 : 14\n",
      "13 : 10\n",
      "74 : 12\n",
      "95 : 12\n",
      "71 : 13\n",
      "80 : 11\n",
      "48 : 8\n",
      "70 : 15\n",
      "39 : 6\n",
      "80 : 11\n",
      "81 : 9\n",
      "26 : 11\n",
      "37 : 13\n",
      "60 : 5\n",
      "75 : 11\n",
      "25 : 6\n",
      "59 : 13\n",
      "87 : 4\n",
      "54 : 9\n",
      "91 : 15\n",
      "63 : 8\n",
      "65 : 6\n",
      "90 : 12\n",
      "68 : 14\n",
      "50 : 8\n",
      "71 : 13\n",
      "0 : 12\n",
      "33 : 11\n",
      "46 : 11\n",
      "77 : 19\n",
      "8 : 9\n",
      "59 : 13\n",
      "14 : 13\n",
      "71 : 13\n",
      "98 : 13\n",
      "73 : 13\n",
      "85 : 11\n",
      "36 : 9\n",
      "68 : 14\n",
      "80 : 11\n",
      "46 : 11\n",
      "3 : 9\n",
      "28 : 11\n",
      "63 : 8\n",
      "6 : 9\n",
      "97 : 14\n",
      "0 : 12\n",
      "22 : 10\n",
      "8 : 9\n",
      "44 : 10\n",
      "48 : 8\n",
      "19 : 13\n",
      "90 : 12\n",
      "41 : 14\n",
      "55 : 8\n",
      "99 : 11\n",
      "68 : 14\n",
      "56 : 9\n",
      "77 : 19\n",
      "19 : 13\n",
      "81 : 9\n",
      "77 : 19\n",
      "52 : 10\n",
      "83 : 7\n",
      "56 : 9\n",
      "37 : 13\n",
      "73 : 13\n",
      "88 : 5\n",
      "71 : 13\n",
      "39 : 6\n",
      "82 : 9\n",
      "32 : 10\n",
      "77 : 19\n",
      "80 : 11\n",
      "58 : 10\n",
      "95 : 12\n",
      "35 : 14\n",
      "27 : 6\n",
      "80 : 11\n",
      "44 : 10\n",
      "48 : 8\n",
      "39 : 6\n",
      "95 : 12\n",
      "23 : 12\n",
      "27 : 6\n",
      "84 : 13\n",
      "51 : 6\n",
      "13 : 10\n",
      "79 : 11\n",
      "35 : 14\n",
      "74 : 12\n",
      "42 : 7\n",
      "77 : 19\n",
      "76 : 11\n",
      "81 : 9\n",
      "40 : 10\n",
      "4 : 8\n",
      "92 : 11\n",
      "64 : 7\n",
      "59 : 13\n",
      "63 : 8\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "x = [random.randint(0,100)for i in range(1000)]\n",
    "print(x)\n",
    "for i in x:\n",
    "    print(i,':',x.count(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "1e580e5a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入下标上限1\n",
      "输入下标下限10\n",
      "输入一个列表[suw,qfjh,eqw]\n",
      "['suw', 'qfjh', 'eqw']\n",
      "['qfjh', 'eqw']\n"
     ]
    }
   ],
   "source": [
    "x = int(input(\"输入下标上限\"))\n",
    "y = int(input(\"输入下标下限\"))\n",
    "z = input(\"输入一个列表\")\n",
    "c=z[1:-1].split(\",\")\n",
    "print(c)\n",
    "print(c[x:y+1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "a98cf5a9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input your thing\n",
      "您输入的键不存在\n"
     ]
    }
   ],
   "source": [
    "d = {'Q':5,'m':9,'t':7}\n",
    "a = input('input your thing')\n",
    "print(d.get(a,'您输入的键不存在'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "7df160f5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6, 14, 18, 22, 34, 48, 54, 60, 82, 93, 97, 80, 75, 74, 65, 58, 57, 50, 13, 9]\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "s = [random.randint(0,100)for i in range(20)]\n",
    "a = sorted(s[:10])\n",
    "b = sorted(s[10:],reverse = True)\n",
    "x = a+b\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1d7a47dd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
